package com.stlm2.controller;

import com.stlm2.dems.service.DdmGoodsService;
import com.stlm2.dems.service.PriceRecordService;
import com.stlm2.dems.service.ValueAddedServicesService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/ddmGoodsC")
public class DdmGoodsController {
    @Resource
    private DdmGoodsService ddmGoodsService;
    @Resource
    private ValueAddedServicesService valueAddedServicesService;

    @Resource
    private PriceRecordService priceRecordService;

    /*
    *zlq
    * 前台商品详情
    * token:
    * id:  商品ID
     */
    @ResponseBody
    @RequestMapping(value="/portalDetails.json",produces="application/json;charset=UTF-8")
    public  String portalDetails(String companyCode,ModelMap model,String id,String token){
        String data=null;
        try {
            data=ddmGoodsService.portalDetails(model,id,token);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
    /*
*zlq
* 前台商品详情
* token:
* id:  商品ID
 */
    @ResponseBody
    @RequestMapping(value="/portalDetails2.json",produces="application/json;charset=UTF-8")
    public  String portalDetails2(String companyCode,ModelMap model,String id,String goodSpecificationId){
        String data=null;
        try {
            data=ddmGoodsService.portalDetails2(model,id,goodSpecificationId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
 *zlq
 * 获取商品增值服务
 * token:
 * id:  商品ID
  */
    @ResponseBody
    @RequestMapping(value="/getGoodsValueAddedServices.json",produces="application/json;charset=UTF-8")
    public  String getGoodsValueAddedServices(String companyCode,ModelMap model,String id){
        String data=null;
        try {
            data=valueAddedServicesService.getGoodsValueAddedServices(model,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
    *zlq
    * 获取价格走势
    * goodsId:商品ID
    * specificationId：规格ID
    *
     */
    @ResponseBody
    @RequestMapping(value="/getPriceRecord.json",produces="application/json;charset=UTF-8")
    public  String getPriceRecord(String companyCode,ModelMap model,String goodsId,String specificationId){
        String data=null;
        try {
            data=priceRecordService.getPriceRecord(model,goodsId,specificationId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }



    /*
*zlq
* 前台商品详情
* token:
* id:  商品ID
*/
    @ResponseBody
    @RequestMapping(value="/guessYouLiveGoods.json",produces="application/json;charset=UTF-8")
    public  String guessYouLiveGoods(String companyCode, ModelMap model,String page,String token){
        String data=null;
        try {
            data=ddmGoodsService.guessYouLiveGoods(model,page,token);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

}
